import 'package:card_swiper/card_swiper.dart';
import 'package:flutter/material.dart';
import 'package:sz/tools/tools.dart';

// 首页
class IndexPage extends StatefulWidget {
  const IndexPage({Key? key}) : super(key: key);

  @override
  IndexPageState createState() => IndexPageState();
}

class IndexPageState extends State<IndexPage> {
  List<Map<String, dynamic>> bannerList = [
    {
      'coverImages':
          'https://dev.shouzhu.com.cn/mybucket/20231117/8deecddbfe4d653f51871bb4247def6e765113e1808f796db6f533fbabf6a2a0.png',
      'title': '住房城乡建设部召开房屋市政工程安全生产治理行动视频调度会议'
    },
    {
      'coverImages':
          'https://dev.shouzhu.com.cn/mybucket/20231117/122552964287897ee11634142101933e0d5290ee6981e49143a66b1a00054b67.png',
      'title': '召开加强城市管理统筹协调暨城市运行管理服务平台建设现场会'
    },
    {
      'coverImages':
          'https://dev.shouzhu.com.cn/mybucket/20231117/6900aabc10dafd1b26f8d56e99f32800deac025e16d6e82783701d563b7e35c6.png',
      'title': '习近平对山西吕梁市永聚煤矿一办公楼火灾事故作出重要指示 李强作出批示'
    }
  ];
//  会议会展
  List<Map<String, dynamic>> meetingList = [
    {
      'homeCoverImage':
          'https://dev.shouzhu.com.cn/mybucket/20231117/075861a771f4d40f40823d96ad16d52ed988d96035ba7418cb64ea8095793595.png',
      'type': 2,
      'title': 'ACT2023（首届）国际零碳城市大会暨零碳建筑博览会'
    },
    {
      'homeCoverImage':
          'https://dev.shouzhu.com.cn/mybucket/20231117/3ffb0fd60436795aad64a5f21b6abbdbe955c5def457b6dfebaf776c39b955ea.png',
      'type': 1,
      'title': '第五届中国智慧供热高峰论坛'
    },
    {
      'homeCoverImage':
          'https://dev.shouzhu.com.cn/mybucket/20231117/958438c18dd087f0a40c7d72ed6d562bb1f7cfa224c0115fc885236cdcfe270e.png',
      'type': 1,
      'title': '第二届青藏高原绿色与零碳建筑发展高端专题论坛暨第八届西南地区建筑绿色化发展年度研讨会'
    },
    {
      'homeCoverImage':
          'https://dev.shouzhu.com.cn/mybucket/20231117/c9576c528ab045962a90149fb3f68b1ff3d00af89799a91904ab40d4dddc21a6.png',
      'type': 1,
      'title': '2023首届青藏高原地区防水技术论坛暨《建筑与市政工程防水通用规范》 实施（西藏）座谈会'
    }
  ];
//新闻资讯
  List<Map<String, dynamic>> newsList = [
    {
      'title': '城市更新试点经验 | 山东烟台：“保留再利用”为城市建设注入新活力',
      'coverImages':
          'https://dev.shouzhu.com.cn/mybucket/20231117/c319cd5387a76d2fd1a7dc429c741a68fe845fb4f1d054e2a1e9c86fba0eaf63.png',
      'creationTime': '2023-11-08 09:08:58'
    },
    {
      'title': '城市更新试点经验 | 重庆渝中区：新动能激发城市“逆生长',
      'coverImages':
          'https://dev.shouzhu.com.cn/mybucket/20231117/2cbe4f5ac77477f76a01312fc8c3cebfdbf92d51d0917941e2f24bf7732b5ef7.png',
      'creationTime': '2023-11-07 11:29:36'
    },
    {
      'title': '经济日报“权威访谈” | 着力构建房地产发展新模式——访住房城乡建设部党组书记、部长倪虹',
      'coverImages':
          'https://dev.shouzhu.com.cn/mybucket/20231117/8deecddbfe4d653f51871bb4247def6e765113e1808f796db6f533fbabf6a2a0.png',
      'creationTime': '2023-11-08 09:08:58'
    },
    {
      'title': '自建房安全专项整治 | 贵州贵阳：坚守房屋安全底线不松动',
      'coverImages':
          'https://dev.shouzhu.com.cn/mybucket/20231117/ad319b4852ae3eb0733c994053b83dd5214d8e0e0956ff4e38911ede4d559fb3.png',
      'creationTime': '2023-11-06 17:17:15'
    }
  ];
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // backgroundColor: Colors.white,
      body: ListView(
        padding: const EdgeInsets.all(0),
        children: [
          // 第一部分
          builderOne(),
          // 第二部分
          builderTwo(bannerList),
          //  标题 通知公告
          builderTitle(
            'images/imgs/index-tongzhi.png',
            const Color(0xfffdf5ef),
          ),
          // 通知公告
          builderNotice(),
          //  标题 会议会展
          builderTitle(
            'images/imgs/index-huiyi.png',
            const Color(0xffecf0fc),
          ),
          //会议会展
          builderMeeting(),
          //  标题 名师讲堂
          builderTitle(
            'images/imgs/index-mingshi.png',
            const Color(0xfff8eded),
          ),
          builderTwo(bannerList),
          // // 名师讲堂 二部分
          builderFamousTwo(),
          //  标题 新闻资讯
          builderTitle(
            'images/imgs/index-xinwen.png',
            const Color(0xfffdf5ef),
          ),
          // 新闻资讯
          builderNews(),
          SizedBox(
            height: rpx(80),
          )
        ],
      ),
    );
  }

  ///新闻资讯
  Container builderNews() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: rpx(24)),
      child: Column(
        children: newsList
            .map((e) => Padding(
                  padding: EdgeInsets.only(bottom: rpx(24)),
                  child: Row(
                    children: [
                      ClipRRect(
                        borderRadius: BorderRadius.circular(rpx(10)),
                        child: Image.network(
                          e['coverImages'],
                          fit: BoxFit.cover,
                          width: rpx(136),
                          height: rpx(136),
                        ),
                      ),
                      SizedBox(
                        width: rpx(30),
                      ),
                      SizedBox(
                        height: rpx(136),
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            SizedBox(
                              width: rpx(500),
                              child: Text(
                                e['title'],
                                maxLines: 2,
                                overflow: TextOverflow.ellipsis,
                              ),
                            ),
                            Text(
                              e['creationTime'],
                              style: TextStyle(
                                  color: SzColor.c9, fontSize: setSp(26)),
                            )
                          ],
                        ),
                      )
                    ],
                  ),
                ))
            .toList(),
      ),
    );
  }

  ///名师讲堂 二部分
  Container builderFamousTwo() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: rpx(24)),
      child: Wrap(
        spacing: rpx(20),
        children: meetingList
            .map((e) => Container(
                  width: rpx(340),
                  margin: EdgeInsets.only(bottom: rpx(24)),
                  child: Column(
                    children: [
                      ClipRRect(
                        borderRadius: BorderRadius.circular(rpx(20)),
                        child: Image.network(
                          'https://dev.shouzhu.com.cn/mybucket/20231117/075861a771f4d40f40823d96ad16d52ed988d96035ba7418cb64ea8095793595.png',
                          fit: BoxFit.cover,
                          width: rpx(340),
                          height: rpx(206),
                        ),
                      ),
                      SizedBox(
                        height: rpx(10),
                      ),
                      const Text(
                        '阿克苏读后感喀什打个卡啦阿是客户端公交卡十多个阿克苏对景挂画',
                        maxLines: 2,
                        overflow: TextOverflow.clip,
                      )
                    ],
                  ),
                ))
            .toList(),
      ),
    );
  }

  ///会议会展
  Container builderMeeting() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: rpx(24)),
      height: rpx(320),
      child: ListView(
        scrollDirection: Axis.horizontal,
        children: meetingList
            .map(
              (e) => Container(
                width: rpx(312),
                margin: EdgeInsets.only(right: rpx(20)),
                child: Column(
                  children: [
                    Stack(
                      children: [
                        ClipRRect(
                          borderRadius: BorderRadius.circular(rpx(20)),
                          child: Image.network(
                            e['homeCoverImage'],
                            fit: BoxFit.cover,
                            width: rpx(312),
                            height: rpx(206),
                          ),
                        ),
                        Positioned(
                          child: Image.asset(
                            e['type'] == 1
                                ? 'images/imgs/index-meeting.png'
                                : 'images/imgs/index-exhibition.png',
                            width: rpx(70),
                          ),
                        ),
                      ],
                    ),
                    SizedBox(
                      height: rpx(10),
                    ),
                    Text(
                      e['title'],
                      style: TextStyle(fontSize: setSp(26)),
                      maxLines: 2,
                      overflow: TextOverflow.clip,
                    )
                  ],
                ),
              ),
            )
            .toList(),
      ),
    );
  }

  ///通知公告
  Container builderNotice() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: rpx(30)),
      child: Column(
        children: [
          Padding(
            padding: EdgeInsets.only(bottom: rpx(24)),
            child: const Text(
              '阿贾克斯大概哈死得更快索拉卡很尬苏卡达干哈凯撒阿萨德更何况',
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
            ),
          ),
          Padding(
            padding: EdgeInsets.only(bottom: rpx(24)),
            child: const Text(
              '阿贾克斯大概哈死得更快索拉卡很尬苏卡达干哈凯撒阿萨德更何况',
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
            ),
          )
        ],
      ),
    );
  }

  ///标题
  Container builderTitle(String url, Color bgColor) {
    return Container(
      margin: EdgeInsets.only(
        left: rpx(24),
        right: rpx(24),
        bottom: rpx(24),
      ),
      padding: EdgeInsets.symmetric(
        horizontal: rpx(20),
        vertical: rpx(24),
      ),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(rpx(16)),
        color: bgColor,
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Image.asset(
            url,
            width: rpx(130),
            height: rpx(45),
          ),
          Row(
            children: [
              Text(
                '查看更多',
                style: TextStyle(fontSize: setSp(26)),
              ),
              Icon(
                Icons.arrow_forward_ios,
                size: rpx(30),
                color: SzColor.c9,
              )
            ],
          )
        ],
      ),
    );
  }

  /// 第二部分
  Container builderTwo(List<Map<String, dynamic>> data) {
    return Container(
      width: getScreenWidth,
      height: rpx(340),
      padding: EdgeInsets.only(left: rpx(24), right: rpx(24), bottom: rpx(24)),
      // decoration: BoxDecoration(color: Colors.red),
      child: ClipRRect(
        borderRadius: BorderRadius.circular(rpx(20)),
        child: Swiper(
          itemWidth: rpx(702),
          itemHeight: rpx(340),
          pagination: SwiperPagination(
            margin: EdgeInsets.all(rpx(20)),
            alignment: Alignment.bottomRight,
          ),
          itemCount: data.length,
          loop: true,
          autoplay: true,
          onTap: (int index) {
            FPrint('banner $index');
          },
          itemBuilder: (BuildContext context, int index) {
            return Stack(children: [
              Positioned.fill(
                child: Image.network(
                  data[index]['coverImages'],
                  fit: BoxFit.fill,
                ),
              ),
              Positioned(
                bottom: rpx(20),
                left: rpx(20),
                child: SizedBox(
                  width: rpx(400),
                  child: Text(
                    data[index]['title'],
                    style: const TextStyle(color: Colors.white),
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                  ),
                ),
              )
            ]);
          },
        ),
      ),
    );
  }

  ///第一部分
  Stack builderOne() {
    return Stack(
      children: [
        SizedBox(
          height: rpx(715),
        ),
        Positioned(child: Image.asset('images/imgs/index-newbage.png')),
        Positioned(
          top: rpx(450),
          height: rpx(270),
          width: rpx(750),
          child: Container(
            width: getScreenWidth,
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(
                  rpx(20),
                ),
                topRight: Radius.circular(
                  rpx(20),
                ),
              ),
            ),
            padding: EdgeInsets.all(rpx(24)),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                InkWell(
                  onTap: () {
                    FPrint('我是服务大厅');
                  },
                  child: Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.all(
                        Radius.circular(
                          rpx(20),
                        ),
                      ),
                      gradient: const LinearGradient(
                        begin: Alignment.topLeft,
                        end: Alignment.bottomRight,
                        colors: [
                          Color(0xff5BC4FB),
                          Color(0xff6589E9),
                        ],
                      ),
                    ),
                    alignment: Alignment.center,
                    width: rpx(190),
                    height: rpx(208),
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Image.asset(
                          'images/imgs/index-fuwdating.png',
                          width: rpx(118),
                          height: rpx(108),
                        ),
                        const Text(
                          '服务大厅',
                          style: TextStyle(color: Colors.white),
                        ),
                      ],
                    ),
                  ),
                ),
                Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Row(
                      children: [
                        builderOneItem(
                          'images/imgs/index-iconlaw.png',
                          '政策法规',
                          const Color(0xffC2E2FF),
                          () {
                            FPrint('政策法规');
                          },
                        ),
                        SizedBox(
                          width: rpx(15),
                        ),
                        builderOneItem(
                          'images/imgs/index-standard.png',
                          '标准规范',
                          const Color(0xffFFE7D1),
                          () {
                            FPrint('标准规范');
                          },
                        ),
                      ],
                    ),
                    SizedBox(
                      height: rpx(16),
                    ),
                    Row(
                      children: [
                        builderOneItem(
                          'images/imgs/index-bidding.png',
                          '招标投标',
                          const Color(0xffFFE6DF),
                          () {
                            FPrint('招标投标');
                          },
                        ),
                        SizedBox(
                          width: rpx(15),
                        ),
                        builderOneItem(
                          'images/imgs/index-education.png',
                          '招标投标',
                          const Color(0xffCEF2DF),
                          () {
                            FPrint('招标投标');
                          },
                        ),
                      ],
                    ),
                  ],
                ),
              ],
            ),
          ),
        ),
      ],
    );
  }

  ///每项
  Widget builderOneItem(
    String imageUrl,
    String title,
    Color bgColor,
    Function? onTap,
  ) {
    return InkWell(
      onTap: () {
        onTap!();
      },
      child: Container(
        decoration: BoxDecoration(
          color: bgColor,
          borderRadius: BorderRadius.circular(rpx(20)),
        ),
        width: rpx(240),
        height: rpx(96),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Image.asset(
              imageUrl,
              width: rpx(44),
              height: rpx(44),
            ),
            SizedBox(
              width: rpx(10),
            ),
            Text(
              title,
              style: TextStyle(fontSize: setSp(28)),
            )
          ],
        ),
      ),
    );
  }
}
